import os

import gradio as gr
from face_feature_ui import create_face_feature_ui
from face_match_ui import create_face_match_ui

# import sys
# from pathlib import Path

# # 确保可以正确导入模块
# sys.path.append(str(Path(__file__).parent))


def create_main_ui():
    """创建主Gradio界面"""
    with gr.Blocks(
        title="媒体处理平台",
        theme=gr.themes.Soft(),
        css=".gradio-container {max-width: 1200px !important}",
    ) as demo:
        gr.Markdown("""
        # 媒体处理平台
        ### 提供人脸特征提取等多媒体处理功能
        """)

        with gr.Tabs():
            with gr.Tab("人脸特征提取", id="face_feature"):
                create_face_feature_ui()
                
            with gr.Tab("人脸匹配", id="face_match"):
                create_face_match_ui()

        # 添加状态显示
        gr.HTML(f"""
        <div style="margin-top: 20px; padding: 10px; background: #f5f5f5; border-radius: 5px;">
            <p>API服务状态: <span id="api-status">检查中...</span></p>
            <p>当前工作目录: {os.getcwd()}</p>
        </div>
        """)

        return demo


if __name__ == "__main__":
    demo = create_main_ui()
    demo.launch(server_name="0.0.0.0", server_port=7870, share=False)
